class hb_class{
    constructor(info){
        this.info = info;
        this.cvs = document.createElement("canvas");
        this.ctx = this.cvs.getContext('2d');
        this.cvs.width = this.info.back.w;
        this.cvs.height = this.info.back.h;
    }
    create(){
		uni.showLoading({
			title: '加载中'
		})
        var t=this;
		return new Promise((resolve,reject)=>{
			t.img_hb_back.onload = function(){
				t.ctx.drawImage(t.img_hb_back, 0, 0, t.info.back.w, t.info.back.h);
				
				t.img_hb_er = new Image();
				t.img_hb_er.crossOrigin="anonymous";
				t.img_hb_er.src=t.info.er.src;
				t.img_hb_er.onload = function(){
					// console.log('load');
					t.ctx.drawImage(t.img_hb_er, t.info.er.pos.left, t.info.er.pos.top, t.info.er.w, t.info.er.h);
					var imageBase64 = t.cvs.toDataURL();
					uni.hideLoading()
					resolve(imageBase64)
				}
			}
		})
		
    }
    init(){
        var t=this;
        t.img_hb_back = new Image();
        t.img_hb_back.crossOrigin="anonymous";
        t.img_hb_back.src=t.info.back.src;
        
    }
}

export {
	hb_class
}

export const totime = (timespan) => {
  // 把时间戳转换成时间字符串 yyyy-MM-dd HH:mm:ss
  const date = new Date(timespan)
  const year = date.getFullYear()
  const month = (date.getMonth() + 1).toString().padStart(2, '0')
  const day = date.getDate().toString().padStart(2, '0')
  const hours = date.getHours().toString().padStart(2, '0')
  const minutes = date.getMinutes().toString().padStart(2, '0')
  const seconds = date.getSeconds().toString().padStart(2, '0')
  const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  return formattedTime
}